package com.chuanyekeji.aokai.Controller;

import com.chuanyekeji.aokai.Entity.AdminUser;
import com.chuanyekeji.aokai.Mapper.AdminUserMapper;
import com.chuanyekeji.aokai.Util.ReturnData;
import com.google.gson.Gson;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;

@Controller
@RequestMapping("admin/")
public class AdminLogin {

    @Autowired
    AdminUserMapper adminUserMapper;

    @RequestMapping("/")
    String login() {
        return "admin/login";
    }

    @RequestMapping("checkLogin")
    @ResponseBody
    String checkLogin(String username, String password, HttpSession session) {
        AdminUser adminUser = adminUserMapper.selectByUsername(username);
        if(adminUser.getPassword().equals(password)) {
            session.setAttribute("user",adminUser);
            return ReturnData.success("success");
        }
        return ReturnData.error(-1,"error");
    }
}
